#pragma once
#include <bondlib/BondDeal/PanoramicBondDealStruct.h>
#include "qbprotocol/include/SSQBModel.h"
#include <widgets/chart/basechart_layoutitem.h>
#include <widgets/chart/basechart_axis.h>
#include <QWidget>
#include <QStylePainter>
#include <vector>
#include <map>
#include <QColor>
#include <QRect>

typedef struct legendInfo
{
	QRect rect;
	bool isShow  = true;
}legendInfo;

namespace{
# define INVALID_FLOAT 1e-18f
}

class BaseChartCustomPlot;
class BaseChartTextElement;
class BaseChartBarsGroup;

class InterestRateBondChart
	: public QWidget
	, public BaseChartCustomAxisGrid
	, public BaseChartCustomTextElement
{
	Q_OBJECT
public:
	typedef enum {
		DATE_WEEK = 0,	//周
		DATE_MONTH		//月
	}DateType;

	InterestRateBondChart(QWidget* p);
	void setDate(int dateType, std::map<int, CRateBondList>* FIGovtBondIssuance);

	// BaseChartCustomTextElement
	virtual bool customDraw(BaseChartPainter* painter, const QRect& rect);

private:
	void initListMap();
	void getDistributionData(std::map<int, CRateBondList>* GovtBondIssuance, CRateBondMap& m_data);
	void countToDistribution(int nType, int week, double IssueAmount, CRateBondMap& data);
	void refresh(int dateType);
	void setRange();
	void showTips(bool& isShow, QMouseEvent* event);
	void setHighLight(QMouseEvent* event);

protected:
	// BaseChartCustomAxisGrid
	virtual bool drawGridXLines(BaseChartPainter* painter) { return true; }
	virtual bool drawGridYLines(BaseChartPainter* painter);

	void paintEvent(QPaintEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;

	void customDraw(BaseChartPainter* painter, const QRect& rect, int count, QColor* clr);

Q_SLOT void click(QMouseEvent* event);
Q_SLOT void hover(QMouseEvent* event);

private:
	BaseChartCustomPlot*	customPlot = nullptr;
	BaseChartTextElement*	m_textElement = nullptr;
	BaseChartBarsGroup*		m_barsGroup = nullptr;
	legendInfo					m_lenendInfo[3];
	CRateBondMap				m_data;
	bool						m_week;
};